<?php
    header('content-type:text/html;charset=utf-8') ;
    
    @include_once('connect.php');
    // echo 'ok';


    // 列表的接口
    // 1 连数据库
    // 2 查询数据库

    $username = $_GET['username'];

//   $username = 'www';
    // 返回给前端的结果
    $obj = [];

    

    // 需要查两张表   购物车这张表+商品列表或者详情表
    // 购物车这表的登录的用户名  需要已经添加到购物车的商品
    $sql = "select * from shoppingcart , flower where username = '$username' and shoppingcart.good_id = flower.goods_id";
    // 执行sql语句   执行之后会得到一个结果集
    $res = mysqli_query($conn , $sql);
    
    $list = [];
    while($data = mysqli_fetch_array($res)) {
        // 把需要的数据留下来
        $temp = [];
        $temp['id'] = $data['goods_id'];
        $temp['title'] = $data['goods_title'];
        $temp['img'] = $data['img'];
        $temp['flower_languae'] = $data['flower_languae'];
        $temp['materials'] = $data['materials'];
        $temp['pack'] = $data['pack'];
        $temp['price'] = $data['price']; 
        $temp['num'] = $data['num'];
        array_push($list , $temp) ;
    }

    if($list) {
        $obj['status'] = true ;
        $obj['data'] = $list ;
    } else {
        $obj['status'] = false ;
        $obj['msg'] = '数据请求失败' ;
    }



    echo json_encode($obj);
?>